<template>
  <el-dialog :title="'续住'" :close-on-click-modal="false" :visible.sync="visible" :append-to-body="true">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="操作" name="first"></el-tab-pane>
      <el-tab-pane label="续住记录" name="second"></el-tab-pane>
    </el-tabs>
    <el-form v-loading="loading" v-show="activeName == 'first'" :model="dataForm" :rules="dataRule" ref="dataForm"
      @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="续住总价" prop="name">
        <el-popover placement="right" width="350" trigger="hover" :disabled="prices.dateList.length==0">
          <el-form label-width="100px" :inline="true" style="max-height: 300px !important;overflow-y: auto;">
            <el-form-item v-for="(item, index) in prices.dateList" :key="index" :label="dateList[index]">
              <el-input @change="changeTotalPrice(prices.dateList)" style="100px" size="small" v-model="item[dateList[index]]"
                placeholder="金额"></el-input>
            </el-form-item>
          </el-form>
          <span slot="reference">
            {{ totlMoney }}
            <i class="el-icon-edit" style="cursor: pointer;"></i>
          </span>
        </el-popover>
      </el-form-item>
      <el-form-item label="入住时间" prop="arrivalsTime">
        <span>{{ dataForm.arrivalsTime }}</span>
      </el-form-item>
      <el-form-item label="预离时间" prop="predissociationTime">
        <span>{{ dataForm.predissociationTime }}</span>
      </el-form-item>
      <el-form-item label="预离变更" prop="changePredissociationTime">
        <el-date-picker @change="dateChange" v-model="dataForm.changePredissociationTime" type="datetime" placeholder="选择日期时间"
          :picker-options="pickerOptions" align="right"></el-date-picker>
      </el-form-item>
      <el-form-item label="续住天数" prop="days">
        <el-input-number v-model="dataForm.days" @change="daysChange" :min="0" label="续住天数"></el-input-number>
      </el-form-item>
      <!-- 付款-->

      <el-form-item size="small" label="收款方式">
        <el-select v-model="dataForm.nowType" placeholder="请选择">
          <el-option v-for="item in options.paysTypeOptions" :key="item.name" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item size="small" label="金额" prop="payPrice">
        <el-input style="width: 199px;" v-model="dataForm.payPrice" placeholder="金额"></el-input>
      </el-form-item>

      <el-form-item label="备注" prop="remarks">
        <el-input v-model="dataForm.remarks" placeholder="备注" type="textarea"></el-input>
      </el-form-item>
    </el-form>
    <span v-show="activeName == 'first'" slot="footer" class="dialog-footer">
      <el-checkbox v-model="xuzhuTiQianCheck" style="margin-right: 10px;">打印续住单</el-checkbox>
      <el-button :disabled="loading" @click="visible = false">取消</el-button>
      <el-button :disabled="loading" type="primary" :loading="btnLoading" @click="dataFormSubmit()">确定</el-button>
    </span>

    <roomcontinuedrecord @pringing="pringingData" v-show="activeName == 'second'" ref="roomcontinuedrecord"></roomcontinuedrecord>

  <el-dialog :visible="dialogshow" title="发门锁卡" :show-close="false" append-to-body class="famensuoka">
     <el-row>
       <el-col :span="12" style="border-right: 1px solid #ccc;text-align: center;padding-right:5px">
         <el-table :data="fjdatalist"  highlight-current-row>
           <el-table-column property="roomSignNum" label="房号" width="100"></el-table-column>
          <el-table-column label="姓名" width="100"  property="pename"></el-table-column>
           <el-table-column property="indexlength" label="写卡数"></el-table-column>
         </el-table>
        <el-tag>合计</el-tag>
         <el-tag>房数: {{fjdatalist.length}}</el-tag>
         <el-tag>卡数: {{kaindex}}</el-tag>
       </el-col>
      <el-col :span="12">
         <el-form ref="form" :model="item" label-width="100px">
           <el-form-item label="客人房号">
             <el-input :disabled="true" v-model="item.roomSignNum"></el-input>
           </el-form-item>
           <el-form-item label="失效时间">
               <el-date-picker :disabled="true" v-model="dataForm.changePredissociationTime" type="datetime" placeholder="选择日期">
               </el-date-picker>
           </el-form-item>
           <el-row style="margin-left: 100px;">
             <el-button @click="DoorNewCard(item)">制新卡</el-button>
             <el-button @click="DoorCopyCard(item)">复制卡</el-button>
             <el-button @click="DoorCancelCard(item)">注销</el-button>
           </el-row>
         </el-form>
       </el-col>
     </el-row>
     <div slot="footer" class="dialog-footer">
       <el-button type="primary" @click="kasave">确 定</el-button>
     </div>
   </el-dialog>

    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" title="请扫描二维码" :visible.sync="payVisible"
      width="30%" append-to-body>
      <div v-loading="payLoding" element-loading-text="正在执行支付">
        <div style="  display: flex;
      justify-content: center;
      align-items: center;margin-bottom:10px">
          <img src="../../../../assets/img/barCode.jpg" />
        </div>

        <div style="text-align:center">支持微信或支付宝条码支付</div>
        <div style="text-align:center">请用条码枪进行扫描</div>
        <span>
          <el-input v-model="auth_no" placeholder="请扫描二维码,支持微信支付宝" @keyup.enter.native="authClose" ref="inputFocus"></el-input>
        </span>
      </div>
    </el-dialog>
    <xz58 v-show="false" id="xz58" ref="xz58" :note="this.printconfig.note"></xz58>
    <xz80 v-show="false" id="xz80" ref="xz80" :note="this.printconfig.note"></xz80>
    <xzA5 v-show="false" id="xzA5" ref="xzA5" :note="this.printconfig.note"></xzA5>
  </el-dialog>







</template>

<script>
  import xz58 from '../../../common/printtemplate/xuzhu_58mm';
  import xz80 from '../../../common/printtemplate/xuzhu_80mm';
  import xzA5 from '../../../common/printtemplate/xuzhu_A5';
  import roomcontinuedrecord from './xuzhu/roomcontinuedrecord.vue';
  import moment from 'moment';
  import {
    getLodop
  } from '../../../../utils/lodop';
  export default {
    data() {
      return {
        activeName: 'first',
        pickerOptions: {
          disabledDate(time) {
            return time.getTime() < Date.now();
          }
        },
        options: {
          paysTypeOptions: [],
        },
        formwaiter: {
          waiterId: "",
          floorRoomId: "",
          creatUserId: "",
          ceeatTime: "",
          remack: "",
          sellerId: "",
        },
        doorLockParams: {
          RoomNumber: "",
          StartDate: "",
          EndDate: "",
          OpeartorType: "",
          CardID: "",
          skr: "",
          sfz: "",
          CardNum: ""
        },
        totlMoney: 0,
        jzId: '',
        auth_no: '',
        kaindex:0,
        prices: {
          dateList: []
        },
        payVisible: false,
        loading: false,
        payInterfaceConfig: {}, //支付
        oldPrice: {
          dateList: []
        },
        istrues:0,
        dateList: [],
        visible: false,
        xuzhuTiQianCheck: false,
        timer: "",
        payLoding: false,
        item: {},
        printconfig: {
          note:''
        },
         dialogshow: false,
        dataForm: {
          payPrice: 0,
          nowType: '',
          arrivalsTime: '',
          remarks: '',
          predissociationTime: '',
          changePredissociationTime: '',
          days: 0
        },
        fjdatalist:[],
          form: {},
        dataRule: {
          sellerId: [{
            required: true,
            message: '商家不能为空',
            trigger: 'blur'
          }]
        },

        btnLoading: false
      };
    },
    components: {
      xz58,
      xz80,
      roomcontinuedrecord,
      xzA5
    },
    methods: {

  kasave(){
   this.dialogshow = false;
   this.visible = false;
   this.$nextTick(() => {
     this.$emit('refreClosing');
     this.$emit('refreshDataList')
   });
  },

      handleClick(tab, event) {
        if (tab.index == 1) {
          this.$refs.roomcontinuedrecord.init(this.item.floorRoomId, this.item.singleId);
        }
      },
      loadPrintConfig() {
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelprinttemplate/info/7`),
          method: 'get'
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.printconfig = data.tHotelPrintTemplate;
          } else {
            this.$message.error(data.msg);
          }
        });
      },
      printXuZhu() {
        this.$nextTick(() => {
          setTimeout(() => {
            LODOP = getLodop();
            if (!LODOP) {
              this.$alert(
                `<br><font color='#FF00FF'>CLodop云打印服务(localhost本地)未安装启动!点击这里<a href='http://www.lodop.net/download/CLodop_Setup_for_Win32NT_4.088Extend.zip' download target='_blank'>执行安装</a>,安装后请刷新页面。</font>`,
                '安装', {
                  confirmButtonText: '确定',
                  dangerouslyUseHTMLString: true
                }
              );
              return;
            }

            //样式
            var strStyleCSS =
              " <link href='https://ebooking.qlan99.com/css/print.css' type='text/css' rel='stylesheet'> ";

            var olstyle1 = '<!DOCTYPE html><html lang="zh-CN"><head>' + strStyleCSS + '</head>' + ' <style> ' +
              'div{border:0!important}' + '</style>';
            var body = '';
            if (this.printconfig.specs === '58mm') {
              var olstyle2 = '<style> .print-wrap-normal{width:' + (58 + parseInt(this.printconfig.printContentOffset)) +
                'mm  !important}</style>';
              body = olstyle1 + olstyle2 + '<body>' + this.$refs.xz58.$refs.xz58.innerHTML + '</body>';
              LODOP.SET_PRINT_PAGESIZE(0, 580, 3000, ''); //设定纸张大小
            }
            if (this.printconfig.specs === '80mm') {
              var olstyle2 = '<style> .print-wrap-normal{width:' + (80 + parseInt(this.printconfig.printContentOffset)) +
                'mm  !important}</style>';
              body = olstyle1 + olstyle2 + '<body>' + this.$refs.xz80.$refs.xz80.innerHTML + '</body>';
              LODOP.SET_PRINT_PAGESIZE(0, 800, 2500, ''); //设定纸张大小
            }
            if (this.printconfig.specs === 'A5') {
              var olstyle2 = '<style> .print-wrap-normal{width:' + (210 + parseInt(this.printconfig.printContentOffset)) +
                'mm  !important}</style>';
              body = olstyle1 + olstyle2 + '<body>' + this.$refs.xzA5.$refs.xzA5.innerHTML + '</body>';
              LODOP.SET_PRINT_PAGESIZE(0, 2100, 2000, ''); //设定纸张大小
            }
            body += '</html>';
            LODOP.ADD_PRINT_HTM(0, 0, 1000, 2000, body); //增加超文本项

            LODOP.SET_PRINT_MODE('PRINT_PAGE_PERCENT', '100%'); //设置缩放
            // LODOP.PRINT_INIT('订单') //打印初始化
            LODOP.SET_PRINT_STYLE('FontSize', 12); //设置对象风格
            LODOP.SET_PRINT_STYLE('Bold', 1); ////设置对象风格
            LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, ''); //设置窗口
            LODOP.SET_PRINT_COPIES(this.printconfig.printSum);

            LODOP.SET_LICENSES("", "4B44F795076C8F14211A5ED0A5339305DAB", "23580B189D96F33252722697A57AC00506B",
              "");

            if (this.printconfig.preview) {
              if (LODOP.SET_PRINTER_INDEXA(this.printconfig.defaultPrint)) {
                LODOP.SET_PRINTER_INDEXA(this.printconfig.defaultPrint);
                LODOP.PRINT();
                // LODOP.PRINT_DESIGN();
              } else {
                LODOP.SET_PRINTER_INDEXA(0);
                LODOP.PRINT();
                // LODOP.PRINT_DESIGN();
              }
            } else {
              if (LODOP.SET_PRINTER_INDEXA(this.printconfig.defaultPrint)) {
                LODOP.SET_PRINTER_INDEXA(this.printconfig.defaultPrint);
                LODOP.PREVIEW();
              } else {
                LODOP.SET_PRINTER_INDEXA(0);
                LODOP.PREVIEW();
                // LODOP.PRINT_DESIGN();
              }
            }
          }, 100)

        });
      },
      dateChange(val) {
        var startDate = moment(this.dataForm.predissociationTime);
        var stopDate = moment(val);
        this.dataForm.days = stopDate.diff(startDate, 'day');
        this.getdateList();
        this.reqRoomPrice();
      },
      daysChange(val, oldValue) {
        //小于入住前一天不能再减
        var arrivalsTime = moment(this.dataForm.arrivalsTime);
        var predissociationTime = moment(this.dataForm.predissociationTime).add(val, 'days');
        console.log(predissociationTime.diff(arrivalsTime, 'day'))
        console.log(moment(this.dataForm.arrivalsTime).add(1, 'days').format("YYYY-MM-DD"))
        console.log(moment(this.dataForm.predissociationTime).add(val, 'days').format("YYYY-MM-DD"))

        if (predissociationTime.diff(arrivalsTime, 'day') < 1 && moment(this.dataForm.arrivalsTime).add(1, 'days').format(
            "YYYY-MM-DD") != moment(this.dataForm.predissociationTime).add(val, 'days').format("YYYY-MM-DD")) {
          this.$nextTick(() => {
            this.dataForm.days = oldValue
          })
          return false
        } else {
          this.dataForm.changePredissociationTime = moment(this.dataForm.predissociationTime).add(val, 'days');
          this.getdateList();
          this.reqRoomPrice();
        }
      },
      //加载日期
      getdateList() {
        this.dateList = [];
        //加载日期
        for (var i = 0; i < this.dataForm.days; i++) {
          this.dateList.push(
            moment(this.dataForm.predissociationTime)
            .add(i, 'days')
            .format('YYYY-MM-DD')
          );
        }
      },
      init(item) {

        console.log(item);
        Object.assign(this.$data, this.$options.data());
        this.visible = true;
        this.item = item;
        this.dataForm.arrivalsTime = item.arrivalsTime;
        this.dataForm.predissociationTime = item.predissociationTime;
        let time = JSON.stringify(item.predissociationTime),
          objClone = JSON.parse(time);
        this.dataForm.changePredissociationTime = objClone;
        this.getPayTypes();
        this.getPayInterface();
        this.getdateList();
        this.loadPrintConfig();
        this.reqRoomPrice();
        if (this.$cookie.get('xuzhuTiQianCheck') != null) {
          if (this.$cookie.get('xuzhuTiQianCheck') == 1) {
            this.xuzhuTiQianCheck = true
          } else {
            this.xuzhuTiQianCheck = false
          }
        }
        // this.oldPrice = item.prices;
        // this.changeTotalPrice(item.oldPrice.dateList);
      },
      //获取支付方式
      getPayTypes() {
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelfloorroompaytype/list'),
          method: 'get',
          params: this.$http.adornParams({
            page: 1,
            limit: 999,
            state: 1,
            isDeposit: 1

          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.options.paysTypeOptions = data.page.list;
            this.dataForm.nowType = this.options.paysTypeOptions[0].id;
          } else {
            this.options.paysTypeOptions = [];
          }
        });
      },
      getPayInterface() {
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelsellerpayinterfaceconfig/myInfo`),
          method: 'get'
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.payInterfaceConfig = data.tHotelSellerPayInterfaceConfig
          } else {
            this.$message.error("加载支付配置失败")
          }
        })
      },
      //续住提前提交
      dataFormSubmit() {

        this.$refs['dataForm'].validate(valid => {
          if (valid) {

            if (this.dataForm.days == 0) {
              this.$message.error("您未做任何改变")
              return
            }

            if (this.xuzhuTiQianCheck) {
              this.$cookie.set('xuzhuTiQianCheck', 1)
            } else {
              this.$cookie.set('xuzhuTiQianCheck', 2)
            }

            console.log("当前配置：", this.payInterfaceConfig)
            if (this.payInterfaceConfig.switchConfig == 1) {
              if (this.payInterfaceConfig.payTypeId === this.dataForm.nowType) {
                if (this.dataForm.payPrice <= 0) {
                  this.$message.error("扫码金额不可小于等于0")
                  return
                } else {
                  this.payVisible = true;
                  this.changeFocus();
                  return
                }
              }
            }

            this.loading = true;
            this.btnLoading = true

            this.$http({
              url: this.$http.adornUrl(`/hotel/thotelfloorroomcheckinpeople/xuzhu`),
              method: 'post',
              data: this.$http.adornData({
                newPrices: JSON.stringify(this.prices),
                id: this.item.id,
                singleId: this.item.singleId,
                floorRoomId: this.item.floorRoomId,
                arrivalsTime: this.dataForm.arrivalsTime,
                predissociationTime: this.dataForm.predissociationTime,
                changePredissociationTime: moment(this.dataForm.changePredissociationTime).format(
                  'YYYY-MM-DD HH:MM'),
                dayin: this.xuzhuTiQianCheck ? 1 : 2,
                remarks: this.dataForm.remarks,
                nowType: this.dataForm.nowType,
                payPrice: this.dataForm.payPrice,
              })
            }).then(({
              data
            }) => {
              this.loading = false;
              if (data && data.code === 0) {
                if (this.xuzhuTiQianCheck) {
                  this.$cookie.set('xuzhuTiQianCheck', 1)
                }


                if (this.xuzhuTiQianCheck) {
                  var pdata = data.data
                  this.$refs.xz58.setData(pdata);
                  this.$refs.xz80.setData(pdata);
                  this.$refs.xzA5.setData(pdata);
                  console.log(pdata);
                }

                this.$message({
                  message: this.$t('Common.OperationSuccessful'),
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    if (this.xuzhuTiQianCheck) {
                      this.printXuZhu();
                      this.btnLoading = false
                    }
                      this.showzhika();


                  }
                });
              } else {
                this.$message.error(data.msg);
                this.btnLoading = false
              }
            });
          }
        });
      },
      showzhika(){
        this.$http({
                  url: this.$http.adornUrl('/hotel/tsellerroomcard/list'),
                  method: 'get',
                  params: this.$http.adornParams({

                  })
                }).then(({data}) => {
                  if (data && data.code === 0) {
                    if(data.page.list!=null&&data.page.list.length!=0){
                        if(data.page.list[0].status==1){
                          this.dialogshow = true;
                          this.fjdatalist.push(this.item);
                        }else{
                            this.visible = false;
                            this.$emit('refreClosing');
                            this.$emit('refreshDataList')
                        }
                    }else{
                       this.visible = false;
                       this.$emit('refreClosing');
                       this.$emit('refreshDataList')
                    }
                  } else {

                  }
               })

      },
      pringingData(pdata) {
        this.$refs.xz58.setData(pdata);
        this.$refs.xz80.setData(pdata);
        this.$refs.xzA5.setData(pdata);
        this.$message({
          message: this.$t('Common.OperationSuccessful'),
          type: 'success',
          duration: 1500,
          onClose: () => {
            this.printXuZhu();
          }
        });
      },

      authClose() {
        // this.payVisible = false;
        this.payLoding = true;
        //扫码支付请求数据
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelsellerpayinterfaceconfig/preAuthBar'),
          method: 'post',
          data: this.$http.adornData({
            'type': 2, //正式
            'auth_no': this.auth_no, //授权码，客户的付款码
            'total_fee': this.dataForm.payPrice * 100, //金额，单位分
            'order_body': '测试', //订单描述
            'attach': '测试', //附加数据,原样返回
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            console.log(data)
            this.payVisible = false
            //保存入账信息
            this.auth_no = "";
            this.payLoding = false;
            var terminalTrace = data.data.terminalTrace
            this.authSubForm(terminalTrace);
          } else if (data.code == 3) {
            //循环查询订单，直至成功或失败
            this.timer = setInterval(() => {
              this.queryOrder(data.data);
            }, 1500);
          } else {
            this.payLoding = false;
            this.auth_no = "";
            this.payVisible = false
            this.$message.error(data.msg);
          }
        })
      },
      queryOrder(data) {
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelsellerpayinterfaceconfig/commonQuery'),
          method: 'post',
          data: this.$http.adornData({
            'pay_type': data.payType,
            'terminal_trace': data.terminalTrace,
            'terminal_time': data.terminalTime,
            'out_trade_no': data.outTradeNo,
          })
        }).then(({
          data
        }) => {
          console.log(data)
          if (data && data.code === 0) {
            clearInterval(this.timer)
            this.payLoding = false;
            console.log(data)
            this.payVisible = false
            this.auth_no = "";
            //保存入账信息
            var terminalTrace = data.data.terminalTrace
            this.authSubForm(terminalTrace);
          } else if (data.code === 3) {

          } else {
            clearInterval(this.timer)
            this.payLoding = false;
            this.payVisible = false
            this.auth_no = "";
            this.$message.error(data.msg);
          }
        })
      },
      authSubForm(terminalTrace) {
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelfloorroomcheckinpeople/xuzhu`),
          method: 'post',
          data: this.$http.adornData({
            collectionNo: terminalTrace,
            newPrices: JSON.stringify(this.prices),
            id: this.item.id,
            singleId: this.item.singleId,
            floorRoomId: this.item.floorRoomId,
            arrivalsTime: this.dataForm.arrivalsTime,
            predissociationTime: this.dataForm.predissociationTime,
            changePredissociationTime: moment(this.dataForm.changePredissociationTime).format(
              'YYYY-MM-DD HH:MM'),
            dayin: this.xuzhuTiQianCheck ? 1 : 2,
            remarks: this.dataForm.remarks,
            nowType: this.dataForm.nowType,
            payPrice: this.dataForm.payPrice,
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            if (this.xuzhuTiQianCheck) {
              this.$cookie.set('xuzhuTiQianCheck', 1)
            }

            this.$nextTick(() => {
              this.$emit('refreClosing');
              this.$emit('refreshDataList')
            });

            if (this.xuzhuTiQianCheck) {
              var pdata = data.data
              this.$refs.xz58.setData(pdata);
              this.$refs.xz80.setData(pdata);
              this.$refs.xzA5.setData(pdata);
              console.log(pdata);
            }

            this.visible = false

            this.$message({
              message: this.$t('Common.OperationSuccessful'),
              type: 'success',
              duration: 1500,
              onClose: () => {
                if (this.xuzhuTiQianCheck) {
                  this.printXuZhu();
                }
              }
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      },
      changeFocus() {
        this.$nextTick(() => {
          this.$refs.inputFocus.focus();
        })
      },
      //计算总金额
      changeTotalPrice(list) {
        // this.totlMoney = 0;
        // list.forEach((item, index) => {
        //   this.totlMoney += parseFloat(item[this.dateList[index]]);
        // });
        // this.totlMoney=Number(this.totlMoney.toString().match(/^\d+(?:\.\d{0,2})?/))
        this.$http({
          url: this.$http.adornUrl(`/hotel/hotelroomprice/getmoney`),
          method: 'post',
          data: this.$http.adornParams({
            startDate: moment(this.dataForm.predissociationTime).format('YYYY-MM-DD'),
            endDate: moment(this.dataForm.changePredissociationTime).format('YYYY-MM-DD'),
            list: JSON.stringify(list)
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.totlMoney = data.hotelRoomPrice
          } else {
            this.$message.error(data.msg);
          }
        });

      },
      reqRoomPrice() {
        console.log(this.item);
        console.log(this.dataForm);
        this.loading = true;
        this.$http({
          url: this.$http.adornUrl(`/hotel/hotelroomprice/list3`),
          method: 'get',
          params: this.$http.adornParams({
            startDate: moment(this.dataForm.predissociationTime).format('YYYY-MM-DD'),
            endDate: moment(this.dataForm.changePredissociationTime).format('YYYY-MM-DD'),
            ids: this.item.roomId,
            floorRoomId: this.item.floorRoomId,
            sid: this.item.singleId
          })
        }).then(({
          data
        }) => {
          this.loading = false;
          if (data && data.code === 0) {
            console.log(this.prices);
            this.prices = data.data.dataList[0];
            this.changeTotalPrice(this.prices.dateList);
          } else {
            this.$message.error(data.msg);
          }
        });
      },


      //制卡
      DoorNewCard(item2) {
         this.item.indexlength = this.item.indexlength + 1;
        this.kaindex = this.kaindex + 1;
        this.doorLockParams.OpeartorType = "NewCard";
        this.getkk(item2);
      },
      //注销卡
      DoorCancelCard(item) {

        this.doorLockParams.OpeartorType = "CancelCard";
        this.getkk(item);
      },

      //复制卡
      DoorCopyCard(item2) {
        this.item.indexlength = this.item.indexlength + 1;
        this.kaindex = this.kaindex + 1;
        this.doorLockParams.OpeartorType = "CopyCard";
        this.getkk(item2);
      },
      getkk(item2) {
        // methods["id"]=
        // console.log(methods)
        var result;
        this.$http({
          url: this.$http.adornUrl(`/hotel/business/Write`),
          method: 'post',
          data: this.$http.adornParams({
            id: item2.floorRoomId,
            singleId: item2.singleId
          })
        }).then(({
          data
        }) => {
          this.doorLockParams.RoomNumber = data.roomNumber;
          this.doorLockParams.StartDate = data.StartDate;
          this.doorLockParams.EndDate = data.endDate;
          this.doorLockParams.CardID = data.CardID;
          this.doorLockParams.skr = data.skr;
          this.doorLockParams.sfz = data.sfz;
          this.doorLockParams.floorCengId = data.floorCengId
          this.doorLockParams.floorId = data.floorId
          this.doorLockParams.CardNum = data.CardNum;
          this.doorWriteCard(this.doorLockParams);
        });
      },
      doorWriteCard(doorLockParams) {
        var postData = {
          DeviceType: "DoorLockHareware",
          Params: JSON.stringify(doorLockParams)
        };
        this.Posts(postData, "Write");
      },
      isputile(istrues, that) {
        setTimeout(function() {
          if (istrues == 0) {
            that.$message({
              message: "接口程序未打开，请打开接口程序",
              type: "error",
              duration: 1500
            });
          }
        }, 2000);

      },
      Posts(postData, methods) {
        console.log(postData)
        var result;
        this.istrues = 0;
        this.axios({
          url: this.axios.postUrl(`/api/Service/` + methods),
          method: 'POST',
          data: postData,
          cache: false,
          async: false,
          contentType: "application/json",
        }).then(({
          data
        }) => {

          if (data.isSuccess == true) {
            this.istrues = 1;
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 1500
            });
            this.savedataForm();
          } else {
            this.istrues = 1;
            this.$message({
              message: data.message,
              type: "error",
              duration: 1500
            });
          }

        })



      },
      savedataForm() {
        this.dataFormsa.skTime = this.doorLockParams.StartDate
        this.dataFormsa.zkUser = this.doorLockParams.skr
        this.dataFormsa.roomNum = this.doorLockParams.CardNum
        this.dataFormsa.kaNo = this.doorLockParams.RoomNumber
        this.dataFormsa.endTime = this.doorLockParams.EndDate
        this.dataFormsa.creatTime = this.doorLockParams.StartDate
        this.dataFormsa.floorCengId = this.doorLockParams.floorCengId
        this.dataFormsa.floorId = this.doorLockParams.floorId


        if (this.doorLockParams.OpeartorType == "NewCard") {
          this.dataFormsa.operation = "制新卡";
        } else if (this.doorLockParams.OpeartorType == "CopyCard") {
          this.dataFormsa.operation = "复制卡";
        } else {
          this.dataFormsa.operation = "注销卡";
        }
        this.$http({
          url: this.$http.adornUrl(`/hotel/tgatecard/save`),
          method: 'post',
          data: this.$http.adornData({
            'skTime': this.dataFormsa.skTime,
            'zkUser': this.dataFormsa.zkUser,
            'roomNum': this.dataFormsa.roomNum,
            'kaNo': this.dataFormsa.kaNo,
            'creatUserId': "",
            'sid': this.sid,
            'endTime': this.dataFormsa.endTime,
            'ckSfz': this.dataFormsa.ckSfz,
            'operation': this.dataFormsa.operation,
            'creatTime': this.dataFormsa.creatTime,
            'floorCengId': this.dataFormsa.floorCengId,
            'floorId': this.dataFormsa.floorId
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {

          } else {
            this.$message.error(data.msg)
          }
        })
      }


    }
  };
</script>

<style></style>
